package com.novabluetooth.services.servicedevices;

import com.novabluetooth.services.TJBluetoothLeService;

import android.bluetooth.BluetoothGattService;
import android.util.Log;

/**
 *体重诺安
 * 
 * @author nova
 *
 */
public class TiZhongNovaService extends TJBluetoothLeService {
	private String TF_readData = "FF0000005A0100A4";
	private String TF_closeDevice = "FF000000500000AF";
	@Override
	public void servicesDiscovered() {
		super.servicesDiscovered();
		BluetoothGattService gattService = mBluetoothGatt.getService(serviceUUID);
		readGattCharact = gattService.getCharacteristic(readCharactUUID);
		writeGattCharact = gattService.getCharacteristic(writeCharactUUID);
		mBluetoothGatt.setCharacteristicNotification(readGattCharact, true);
		ifSuccess = writeDataToDevice(TF_readData);
	}

	@Override
	public boolean isRightData(byte[] buffer) {
		super.isRightData(buffer);

		// 体温
		int readSize = buffer.length;
		if (readSize <= 0) {
			Log.e( TAG , "readSize《=0");
			ifSuccess = false;
		}

		else if (readSize < 8) {
			Log.e(TAG, "readSize《=8");
			ifSuccess = false;
		} else {

			String getDate = byteArray2HexString(buffer, readSize);
			System.out.println("获取到的数据为：  " + byteArray2HexString(buffer, readSize));

			int tf = Integer.parseInt(getDate.substring(10, 14), 16);

			float bg = (float) (tf / 10.0);
			// checkData = "体温:" + bg;
			checkData = String.valueOf(bg);
			ifSuccess = true;
		}
		return ifSuccess;

	}

	@Override
	public void closeDevice() {
		super.closeDevice();
		ifSuccess = writeDataToDevice(TF_closeDevice);
	}

}
